// pages/distribut/today_order/today_order.js
var app = getApp();
var request = app.request;
var setting = app.globalData.setting;
var common = require('../../../utils/common.js');
var util = require('../../../utils/util.js');
import LoadMore from '../../../utils/LoadMore.js'
var load = new LoadMore;

Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		url: setting.url,
		currentTab: 1,
		page: 3,
		one: 0,
		two: 0,
		three: 0,
		currentPage: 1,
		teamList: null,
		type: '3',
	
		word: "",
		time: app.getym(),
		currentdate: {
			hao: new Date().getDate(),
			zj: new Date().getDay(),
			datedq: app.globalData.parseTime(new Date(), '{y}-{m}-{d}'),
			nianyuer: app.globalData.parseTime(new Date(), '{y}年{m}月{d}日'),
		},
		currentlist: app.getDate(new Date()),
		zlist: ['周日', '周一', '周二', '周三', '周四', '周五', '周六', ],
		list: []
	},
	itemclick(e) {
		this.setData({
			time: app.globalData.parseTime(e.detail, '{y}年{m}月'),
			currentlist: app.getDate(e.detail),
			currentdate: {
				hao: new Date(e.detail).getDate(),
				zj: new Date(e.detail).getDay(),
				datedq: app.globalData.parseTime(e.detail, '{y}-{m}-{d}'),
				nianyuer: app.globalData.parseTime(e.detail, '{y}年{m}月{d}日')
			},
			currentPage: 1,
			list: []
		})
		this.getTeamList()
	},
	itemclick1(e) {
		this.setData({
			currentdate: e.detail,
			currentPage: 1,
			list: []
		})
		this.getTeamList()
	},
	inpute(value, cursor, keyCode) {
		this.setData({
			word: value.detail.value,
			currentPage: 1,
			list: []
		})
		this.getTeamList()
	},
	// 申请退款等跳转操作
	staterefund(e) {
		let that = this
		request.get('/api/shop/returnGood', {
			data: {
				rec_id: e.currentTarget.dataset.id
			},
			success: function(res) {
				if (res.data.status == 1 && res.data.result) {
					wx.navigateTo({
						url: '/pages/distribut/request_refund/request_refund?rec_id=' + e
							.currentTarget.dataset.id
					});
				}
			}
		});
	},
	// 拨打电话
	tels(e) {
		wx.makePhoneCall({
			phoneNumber: e.currentTarget.dataset.id,
		})
	},
	// 复制订单号
	viewCopyTextClick(e) {
		var _this = this
		wx.setClipboardData({
			data: e.currentTarget.dataset.id,
			success: function(res) {
				wx.getClipboardData({
					success: function(res) {
						wx.showToast({
							title: '复制成功'
						})
					}
				})
			}
		})
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(e) {
	
		load.init(this, 'lists', 'teamList');
		this.getTeamList();

	},


	ddd(e) {
		var that = this;
		that.setData({
			type: e.currentTarget.dataset.id.id,
			list: [],
			currentPage: 1,
		})

		this.getTeamList(this.data.currentTab);
	},

	getTeamList: function() {
		var that = this;
		load.request('/api/shop/getOrderList?day_time=' + that.data.currentdate.datedq + '&order_type=' +
			that.data.type + '&order_sn=' +
			that.data.word + '&page_no=' + that.data.currentPage + '&page_size=' + that.data.page,
			function(
				res) {
				if (res.data.status == 1 && res.data.result.data.length != 0) {
					that.data.currentPage++;
					let datalist = that.data.list.concat(res.data.result.data || [])
					that.setData({
						list: datalist,
						currentTab: res.data.result.count
					})
				}
				wx.stopPullDownRefresh();
			});
	},
	//事件处理函数
	clickTab: function(e) {
		var that = this;
		if (that.data.currentTab != e.target.dataset.current) {
			that.setData({
				currentTab: e.target.dataset.current,
			})
			that.resetData();
			that.getTeamList();
		}
	},
	distributTopages: function(e) {
		common.todistribut(e.currentTarget.dataset.idx, this.data.page);
	},
	//重置数据
	resetData: function() {
		load.resetConfig();
		this.data.teamList = null;
		this.data.currentPage = 1;
	},

	onReachBottom: function() {
		if (Math.ceil(this.data.currentTab) > this.data.currentPage) {
			this.getTeamList();
		}
	},
	onShareAppMessage(e) {
		return {
			title: e.target.dataset.item.goods_name,
			path: '/pages/goods/goodsInfo/goodsInfo?goods_id=' + e.target.dataset.item.goods_id
		}
	},

	onPullDownRefresh: function(e) {
		this.resetData();
		this.getTeamList();
	}
})